package cn.tedu.cms.controller;


import cn.tedu.cms.entity.CrmBanner;
import cn.tedu.cms.service.CrmBannerService;
import cn.tedu.commonUtils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author hong
 * @since 2023-05-22
 */
@RestController
@RequestMapping("/cms/banner")
@CrossOrigin
public class FrontBannerController {
    @Autowired
    private CrmBannerService bannerService;

    @ApiOperation(value = "获取首页banner")
    @GetMapping("getAllBanner")
    @Cacheable(key = "'selectIndexList'",value = "banner")
    public R index() {
        LambdaQueryWrapper<CrmBanner> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(CrmBanner::getId);
        wrapper.last("limit 2");
        List<CrmBanner> list = bannerService.list(wrapper);
        return R.ok().data("bannerList", list);
    }

}

